package com.stockz.scanner.screen;

import java.util.List;

import com.stockz.core.model.Bar;
import com.stockz.scanner.screen.configuration.SimpleConsolidationScreenConfiguration;

public class SimpleConsolidationBreakoutScreen implements Screen<SimpleConsolidationScreenConfiguration> {

	private SimpleConsolidationScreenConfiguration configuration
				= new SimpleConsolidationScreenConfiguration();
	
	@Override
	public SimpleConsolidationScreenConfiguration getConfiguration() {
		return configuration;
	}

	@Override
	public int getMandatorySpan() {
		return configuration.getSpan()+1;
	}

	@Override
	public boolean isMatch(List<Bar> barList) {
		double max = Double.MIN_VALUE;
		double min = Double.MAX_VALUE;
		for(int i = 1; i < configuration.getSpan()+1; i++){
			double close = barList.get(i).getClose();
			if(close > max) max = close;
			if(close < min) min = close;
			
			if(max > Double.MIN_VALUE 
					&& min < Double.MAX_VALUE
					&& min != 0){
				if(!(((max-min)*100/min) < configuration.getRangePercentage())){
					return false;
				}
			}
		}
		
		return barList.get(0).getClose() >= max;
	}

}
